﻿@inherits BaseComponent
@typeparam TItem where TItem : class, new()

@if (Model.Tree != null)
{
	<GridRow>
		<GridCol Span="4">
			<div style="padding:10px;">
				<DataTree Model="Model.Tree" />
			</div>
		</GridCol>
		<GridCol Span="20">
			<div class="page-top">
				<QueryForm TItem="TItem" Model="Model.Table" OnSearch="OnSearchAsync" />
			    <Toolbar Items="Model.Tools" OnItemClick="Model.OnToolClick" />
			</div>
			<DataTable @ref="table" TItem="TItem" Model="Model.Table" />
		</GridCol>
	</GridRow>
}
else
{
	<div class="page-top">
		<QueryForm TItem="TItem" Model="Model.Table" OnSearch="OnSearchAsync" />
		<Toolbar Items="Model.Tools" OnItemClick="Model.OnToolClick" />
	</div>
	<DataTable @ref="table" TItem="TItem" Model="Model.Table" />
}

@code {
	DataTable<TItem> table;

	[Parameter] public PageModel<TItem> Model { get; set; }

	protected override void OnInitialized()
	{
		Model.StateChanged = StateHasChanged;
		base.OnInitialized();
	}

	private Task OnSearchAsync() => table.RefreshAsync();
}